﻿namespace KinonekoSoftware.CodariaDB.Core
{
    public enum MusicType
    {
        Mp3,
        Wav,
    }

    public class Music
    {

    }

    public sealed class MusicSystem : _File
    {

        public MusicSystem() : base("Music", ResourceType.Cover)
        {

        }
        
        
        protected override Occupation OnCreate(string id) => new Occupation
        {
            Id       = id,
            FileName = id,
            Usage    = true,
            Type     = ResourceType.Music,
        };

        public Stream OpenCover(string id)
        {
            var fileName = Path.Combine(Folder, string.Format(ImageFilePattern, id));
            var stream   = new FileStream(fileName, FileMode.Open);
            return stream;
        }

        public override Stream Open(string id)
        {
            if (string.IsNullOrEmpty(Folder) || string.IsNullOrEmpty(id))
            {
                return null;
            }

            var fileName = Path.Combine(Folder, string.Format(MusicFilePattern, id));

            if (File.Exists(fileName))
            {
                var stream = new FileStream(fileName, FileMode.Open);
                return stream;
            }

            return null;
        }

        public override async Task WriteAsync(string id, byte[] buffer)
        {

            var fileName = Path.Combine(Folder, string.Format(MusicFilePattern, id));

            //
            //
            await File.WriteAllBytesAsync(fileName, buffer);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="buffer"></param>
        public async Task WriteThumbnailAsync(string id, byte[] buffer)
        {
            var fileName = Path.Combine(Folder, string.Format(ImageFilePattern, id));

            //
            //
            await File.WriteAllBytesAsync(fileName, buffer);
        }


        public override string EngineID => EngineNames.FileDataSet_Image;
    }
}